///@file Connection.h
///@brief Header of class which encapsulates details of data-transfer proccess.
///@author A. Poliukhovych

#pragma once

#include <QObject>
#include <QSharedPointer>


class QTcpSocket;

namespace Networking
{
    class Connection: public QObject
    {
        Q_OBJECT
    public:
        Connection(QTcpSocket* sock);
        void DisconnectFromHost();
        inline int Descriptor() { return m_descriptor; }
        inline void SetDescriptor(int val) { m_descriptor = val; }
        ~Connection();

       QString peerInfo() const;
    public slots:
        void SlotSendData(const QString&);
    signals:
        void SignalNewMessage(const QString&, int sender);
        void SignalConnectionLost();

    private:
        QTcpSocket* m_socket;
        int m_descriptor;

        QByteArray packMessage(const QString& msg) const;
    private slots:
        void SlotReadData();
    };

    typedef QSharedPointer<Connection> ConnectionPtr;
}
